' 下载文件入口
'
' -- 处理
' -- -- 下载目录 定位
' -- -- 文件名 修改
' -- 调用 xml_core.vbs
'
' wscript.shell 处理文件目录名有空格 采用 chr(34)
'
dim url,fileName
objArgs = wscript.arguments(0)

objArgs = Trim(objArgs)
argsString = split(objArgs, ",")

' 长度是2，ubound返回是可用长度 从0开始  为1
argscount = ubound(argsString) + 1

if argscount < 2 then
  msgbox("invalid")
else
  fileName = argsString(0)
  url = argsString(1)
  ' msgbox "doing_down fileName=" & fileName & "    url=" & url
  CoreXMLDownload fileName, url
end if


function CoreXMLDownload(fileName, url)
  Dim fso,currentDir,rootDir
  Dim parentFunc,parentAssets,parentEntry

  set fso = CreateObject("Scripting.FileSystemObject")
  ' 当前目录
  currentDir = fso.GetFile (Wscript.ScriptFullName).ParentFolder.Path

  rootDir = fso.GetFile(Wscript.ScriptFullName).ParentFolder.ParentFolder.ParentFolder.path
  ' msgbox "currentDir=" & currentDir

 ' 时间戳
  UnixTime = DateDiff("s", "01/01/1970 00:00:00", Now())

  extentName = fso.GetExtensionName(fileName)
  extentIndex = InStrRev(fileName, "." & extentName)
  newFileName = Left(fileName, extentIndex)
  newFileName = newFileName & "_" & UnixTime & "." & extentName


  download_path =  rootDir & "\download\" &newFileName
  msgbox "download_path=" & download_path

  set ws = wscript.CreateObject("wscript.shell")

  wsvbs = chr(34) & currentDir & "\xml_core.vbs " & chr(34)
  wsargs = url & "," & chr(34) & download_path & chr(34)

  ' msgbox "wsvbs=" & wsvbs
  ' msgbox "wsargs=" & wsargs

  ws.run wsvbs & wsargs, 0, true

  ' msgbox "download node.msi success"
end function
